From de36dda9251f4f60b0be575231974f3ab7bd879e Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 10 Jan 2011 20:45:23 +0100 Subject: [PATCH] Add gtk_style_context_scroll_animations() This function will be needed in widgets like GtkTreeView, since gdk_window_scroll() doesn't trigger the usual mechanisms to update the invalidation area, this function is needed together with it. --- docs/reference/gtk/gtk3-sections.txt | 1 + gtk/gtk.symbols | 1 + gtk/gtkstylecontext.c | 70 ++++++++++++++++++++++++++++ gtk/gtkstylecontext.h | 4 ++ 4 files changed, 76 insertions(+) diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index b52ea6a167..2646f6e85d 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -5574,6 +5574,7 @@ gtk_style_context_notify_state_change gtk_style_context_pop_animatable_region gtk_style_context_push_animatable_region gtk_style_context_cancel_animations +gtk_style_context_scroll_animations gtk_style_context_remove_provider gtk_style_context_remove_provider_for_screen gtk_style_context_reset_widgets diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 3625120374..1f99b02cf0 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -2499,6 +2499,7 @@ gtk_style_context_remove_region gtk_style_context_reset_widgets gtk_style_context_restore gtk_style_context_save +gtk_style_context_scroll_animations gtk_style_context_set_background gtk_style_context_set_direction gtk_style_context_set_junction_sides diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index 3d1b0aa530..bad7409a90 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -2965,6 +2965,76 @@ gtk_style_context_cancel_animations (GtkStyleContext *context, } } +static gboolean +is_parent_of (GdkWindow *parent, + GdkWindow *child) +{ + GtkWidget *child_widget, *parent_widget; + GdkWindow *window; + + gdk_window_get_user_data (child, (gpointer *) &child_widget); + gdk_window_get_user_data (parent, (gpointer *) &parent_widget); + + if (child_widget != parent_widget && + !gtk_widget_is_ancestor (child_widget, parent_widget)) + return FALSE; + + window = child; + + while (window) + { + if (window == parent) + return TRUE; + + window = gdk_window_get_parent (window); + } + + return FALSE; +} + +/** + * gtk_style_context_scroll_animations: + * @context: a #GtkStyleContext + * @window: a #GdkWindow used previously in + * gtk_style_context_notify_state_change() + * @dx: Amount to scroll in the X axis + * @dy: Amount to scroll in the Y axis + * + * This function is analogous to gdk_window_scroll(), and + * should be called together with it so the invalidation + * areas for any ongoing animation are scrolled together + * with it. + * + * Since: 3.0 + **/ +void +gtk_style_context_scroll_animations (GtkStyleContext *context, + GdkWindow *window, + gint dx, + gint dy) +{ + GtkStyleContextPrivate *priv; + AnimationInfo *info; + GSList *l; + + g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); + g_return_if_fail (GDK_IS_WINDOW (window)); + + priv = context->priv; + l = priv->animations; + + while (l) + { + info = l->data; + l = l->next; + + if (info->invalidation_region && + (window == info->window || + is_parent_of (window, info->window))) + cairo_region_translate (info->invalidation_region, dx, dy); + } +} + /** * gtk_style_context_push_animatable_region: * @context: a #GtkStyleContext diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h index ceedc529c0..309e2755b5 100644 --- a/gtk/gtkstylecontext.h +++ b/gtk/gtkstylecontext.h @@ -524,6 +524,10 @@ void gtk_style_context_notify_state_change (GtkStyleContext *context, gboolean state_value); void gtk_style_context_cancel_animations (GtkStyleContext *context, gpointer region_id); +void gtk_style_context_scroll_animations (GtkStyleContext *context, + GdkWindow *window, + gint dx, + gint dy); void gtk_style_context_push_animatable_region (GtkStyleContext *context, gpointer region_id); -- 2.30.2